﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using Instances.Contracts;

namespace Umbrella.Net.Contracts
{
    #region structs

    public class UmbrellaReleaseInfo : ReleaseInfo
    {
        public int SharePointBuildId;
        public string SharePointVersionString;

        public UmbrellaReleaseInfo()
        {
        }

        public UmbrellaReleaseInfo(ReleaseInfo lr)
        {
            if (lr == null)
                throw new ArgumentNullException("lr");

            this.ProductId = lr.ProductId;
            this.ReleaseId = lr.ReleaseId;
            this.ReleaseUrl = lr.ReleaseUrl;
            this.MsiDownloadUrl = lr.MsiDownloadUrl;
            this.VersionString = lr.VersionString;
        }
    }

    public struct SharePointVersionInfo
    {
        public int BuildNumber;
        public string VersionString;
    }

    public struct SharePointLanguage
    {
        public int LCID;
        public string Title;
        public string ISO;
    }

    public enum SharePointPlatform
    {
        X86,
        X64
    }

    public struct SharePointInstallationFile
    {
        public int LanguageLCID;
        public SharePointPlatform Platform;
        public Guid ProductCode;
        public string ZipDownloadUrl;
        public string ZipPassword;

        public string GetZipFilename()
        {
            if (string.IsNullOrEmpty(this.ZipDownloadUrl))
                return null;

            var segs = new Uri(this.ZipDownloadUrl).Segments;

            if (segs.Length <= 0)
                return null;

            return segs[segs.Length - 1];
        }
    }

    #endregion

    partial interface IUmbrellaService
    {
        [OperationContract]
        UmbrellaReleaseInfo GetLatestVersion(LatestVersionQuery query);

        [OperationContract]
        void ReportError(ErrorInfo error);

        [OperationContract]
        IEnumerable<SharePointVersionInfo> GetSharePointVersions();

        [OperationContract]
        IEnumerable<SharePointLanguage> GetSharePointLanguages();

        [OperationContract]
        IEnumerable<SharePointInstallationFile> GetSharePointInstallationFiles(int buildNumber);

        [OperationContract]
        int GetBestMatchingBuildNumber(int buildNumber);
    }
}


